
<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">

<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<script type="text/javascript" src="/easyui/datagrid-detailview.js"></script>

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Project，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
    <!-- 主表  -->
    <table id="project_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
           data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/project-list/4/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  onDblClickRow:onDblClickRow,
					  onRowContextMenu: onRowContextMenu,
					  onLoadSuccess:function(data){
                            $('.edit').linkbutton({plain:true,iconCls:'icon-edit'});
                            $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                            $('.next').linkbutton({plain:true,iconCls:'icon-active'});
                            $('.upload').linkbutton({plain:true,iconCls:'icon-upload'});
                   },
					  showFooter: true" >
        <thead>
            <tr>
                <th data-options="field:'id',width:40,align:'center' ,formatter:idFormatter"></th>
                <th data-options="field:'proName',width:200,align:'center' ">项目名称</th>
                <th data-options="field:'proJueCeInvestCorpus',width:200,align:'center' ">投资主体</th>
                <th data-options="field:'proRealInvestmentTime',width:200,align:'center' ">投资时间</th>
                <th data-options="field:'proPaymentMoney',width:200,align:'center' ">投资金额</th>
                <th data-options="field:'proRealProportion',width:200,align:'center' ">股比</th>
                <#--<th data-options="field:'userId',width:100,align:'center' ,formatter:userIdFormatter">业务人员</th>-->
                <#--<th data-options="field:'proState',width:100,align:'center' ,formatter:proStateFormatter ">项目状态</th>-->
                <th data-options="field:'proJueCeInvestType',width:100,align:'center'">投资状态</th>
            </tr>
        </thead>
    </table>
</div>

<div id="dialog_upload" class="easyui-dialog" title="上传资料" data-options="closed:true,modal:true,border:'thin'" style="width: 600px; height: 150px; padding: 5px;">
    <div style="padding: 10px">
        <form id="form_upload" method="post" enctype="multipart/form-data" target="upload">
            <table>
                <tr>
                    <td>
                        <input type="file" name="upload" id="upload" style="width: 400px;" class="easyui-validatebox"  required="true"/>
                        <input hidden id="id" >
                    </td>
                </tr>
            </table>
        </form>
        <iframe name="upload" style="display: none"></iframe>
    </div>
    <div style="text-align: right; padding: 5px;">
        <a id="btn_upload" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)">上传</a>
        <a id="btn_cancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)">取消</a>
    </div>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>


        项目名称:
        <input class="easyui-textbox" name="proName"id="proName">
        投资类型:
        <input class="easyui-combobox" name="proJueCeInvestType"id="proJueCeInvestType" data-options="
				url : '/constants/project_invest_type',
				method: 'get',
				valueField:'key',
				textField:'value',
        ">
        项目编号:
        <input class="easyui-textbox" name="proId"id="proId">
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>

<!-- 右键 -->
<div id="right_click" class="easyui-menu" style="width:120px;">
    <div onclick="nx()" data-options="iconCls:'icon-add'">退出</div>
    <div onclick="yc('N')" data-options="iconCls:'icon-cancel'">异常</div>
    <div onclick="yc('Y')" data-options="iconCls:'icon-cancel'">否决</div>
    <div class="menu-sep"></div>
    <div onclick="query()" data-options="iconCls:'icon-add'">查看</div>
    <div onclick="projectExport()" data-options="iconCls:'icon-upload'">导出</div>
</div>

<script type="text/javascript">

    $("#searchByParameter").click(function(){

        var proName = $("#proName").val();
        var proJueCeInvestType = $("#proJueCeInvestType").val();
        var proId = $("#proId").val();
        var handler = '/project-list/4/1/20?proId='+proId+
            "&proName="+proName+"&proJueCeInvestType="+proJueCeInvestType;
        $('#project_table').datagrid('options').url = handler;
        $('#project_table').datagrid('reload');
    });

    function idFormatter(value,row) {
        var button ='';
        var url = '/project-touhou-zhitou-edit/' + value;
        button += '<a class="edit" data-title="'+row.proName+'--投后管理" data-href="'+url+'" onclick="Hui_admin_tab(this)" href="javascript:;"></a>'
        return button;
    }
    function  proCategoryFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_category/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function proStateFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_state/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    // function userIdFormatter(val){
    //     var result = '';
    //     $.ajax({
    //         url : '/user-get/'+val,
    //         async : false,
    //         success :function (data) {
    //             result = data;
    //         }
    //     })
    //     return result;
    // }

    function cellStyler(value,row,index){
        if (value == 1){
            return 'background-color:#ffee00;color:red;';
        }
    }
    function proTouziFlagFormatter(value) {
        if(1==value){
            return '信息已填报';
        }
        return ''
    }

</script>

<!-- 按钮操作 -->
<script type="text/javascript">

    $('#export').click(function(){
        var url = "/finance-download/4";
        window.location = url;
    });

    function projectExport() {
        var node = $('#project_table').datagrid('getSelected');
        if(null != node && "" != node){
            var id = node.id;
            var url = '/projectInfo-validate/'+id;
            var index = layer.open({
                title:'项目明细',
                type: 2,
                area: ['700px', '450px'],
                fixed: true, //不固定
                maxmin: true,
                content: url
            });
            layer.full(index);
        }else {
            layer.msg("请选择数据！");
        }
    }

    function edit(value) {
        var url = '/project-touhou-edit/'+value;
        var index = layer.open({
            title:'投后管理',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    }

    //行复制
    $("#copy").click(function () {
        layer.msg('行复制');
    })
    //------删除开始
    $("#delete").click(function () {
        var row = $('#project_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要删除的项目",{icon: 2})
        }else{
            url = '/project-ins-upd-del/'+row.id;
            $.messager.confirm('删除信息','确定删除此项目?',function(r){
                if (r){
                    $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                        $('#project_table').datagrid('reload');    // reload the user data
                    });
                }
            });
        }
    });

    function del(value){
        layer.confirm('确定删除用户？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/project-ins-upd-del/'+value,
                data : {deleteFlag:'Y',tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#project_table').datagrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    }
    //------删除结束

    function next(value){
        layer.confirm('确定审核通过？', {
            btn: ['审核','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/project-ins-upd-del/'+value,
                data : {proState:5,tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#project_table').datagrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    }

    //上传开始
    function upload_info(value){
        $('#dialog_upload').dialog('open').dialog('center');
        $('#id').val(value);
    }

    $('#btn_upload').click(function(){
        var id = $('#id').val();
        $("#form_upload").form('submit', {
            type: 'post',
            url: '/upload-file/'+id,
            onSubmit: function (param) {
            },
            success: function (data) {
                $('#dialog_upload').dialog('close');        // close the dialog
                var handler = '/project-list/4/1/20';
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
            }
        });
    });

    $('#btn_cancel').click(function(){
        $('#dialog_upload').dialog('close');
    })
    //上传结束

</script>

<!-- 分页 -->
<script type="text/javascript">
    $(function(){
        var p = $('#project_table').datagrid().datagrid('getPager');
        p.pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 40, 60], //可以设置每页记录条数的列表
            onSelectPage: function (pageNumber, pageSize) {
                if(pageNumber==0){
                    pageNumber = 1;
                }
                var proId = $("#proId").val();
                var proName = $("#proName").val();
                var proJueCeInvestType = $("#proJueCeInvestType").val();
                var handler = '/project-list/4/'+pageNumber+"/"+pageSize+"?proId="+proId+
                    "&proName="+proName+"&proJueCeInvestType="+proJueCeInvestType;
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
            }
        });
    })
</script>

<!-- 右键操作 -->
<script>
    function onRowContextMenu(e,row){
        e.preventDefault();
        var node = $('#project_table').datagrid('getSelected');
        if(node){
            $('#right_click').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }
    }
    function onDblClickRow(rowIndex,rowData){
        var id = rowData.id;
        var title = rowData.proName;
        var url = '/project-touhouZT-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }

    function nx(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        layer.confirm('确定审核通过？', {
            btn: ['审核','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/project-ins-upd-del/'+id,
                data : {proState:5,tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#project_table').datagrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });


    }
    function de(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var proName = node.proName;

        layer.confirm('确定删除该项目(项目名称：'+proName+  ')？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/project-ins-upd-del/'+id,
                data : {deleteFlag:'Y',tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#project_table').datagrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    }
    function query() {
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var title = node.proName;
        var url = '/project-touhouZT-view/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }
    function up(){
        var node = $('#project_table').datagrid('getSelected');
        var id = node.id;
        var url = '/common-upload/'+id+'/4';
        var index = layer.open({
            title:'资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);
    }

    function yc(val){
        var ycOrVeto = '';
        if(val == 'N'){
            ycOrVeto = '此项目被标记为异常，请描述异常原因';
        }else {
            ycOrVeto = '此项目被否决，请描述否决原因';
        }
        layer.prompt({title: ycOrVeto, formType: 2}, function(text, index){
            layer.close(index);
            var node = $('#project_table').datagrid('getSelected');
            $.ajax({
                type :'post',
                url : '/errorproject-set/'+val+'/'+node.id+'/',
                data : {reason:text,state:'投后阶段'},
                async :false,
                success :function(){
                    var handler = '/project-list/4/'+1+"/"+20;
                    $('#project_table').datagrid('options').url = handler;
                    $('#project_table').datagrid('reload');
                }
            });
        });
    }
</script>